package model

import (
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
	"log"
	"myGame/src/Config"
	"time"
)

type Protect struct {
	Image    *ebiten.Image
	LastTime time.Time
	Display  bool
	X        int
	Y        int
}

func NewProtect(screenWidth, screenHeight int) *Protect {
	protectpng, _, err := ebitenutil.NewImageFromFile("./src/images/protect.png")
	if err != nil {
		log.Fatal(err)
	}

	protect := &Protect{
		Image:    protectpng,
		LastTime: time.Now(),
		Display:  true,
		X:        0,
		Y:        0,
	}
	return protect
}

// 单独书写一个声明值的方法，方便后续管理
func (protect *Protect) Draw(screen *ebiten.Image, cfg *Config.Config, r *Realm) {
	op := &ebiten.DrawImageOptions{}
	var Y float64
	if r.State == 1 {
		Y = r.Y[r.State] - 50
	} else {
		Y = r.Y[r.State]
	}
	if protect.Display {
		op.GeoM.Translate(r.X, Y)
		screen.DrawImage(protect.Image, op)
	}
}
